﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Win32;

namespace HealthCenter
{
    public partial class SystemConfigForm : Form
    {
        public SystemConfigForm()
        {
            InitializeComponent();
            ProxyConfigure pc = GetConfig();
            txtProxyHost.Text = pc.Host;
            txtProxyUserName.Text = pc.UserName;
            txtProxyPassword.Text = pc.Password;
            cbUseProxy.Checked = (true == pc.ProxyEnabled);
        }

        private void Config(bool enable)
        {
            txtProxyHost.Enabled = enable;
        }

        public static ProxyConfigure GetConfig()
        {
            RegistryKey rk = Application.CommonAppDataRegistry;
            ProxyConfigure pc = new ProxyConfigure();
            pc.Host = (string)rk.GetValue("host");
            pc.UserName = (string)rk.GetValue("userName");
            pc.Password = (string)rk.GetValue("password");
            string o = (string)rk.GetValue("proxyEnabled");
            if ("True".Equals(o, StringComparison.OrdinalIgnoreCase))
            {
                pc.ProxyEnabled = true;
            }
            else
            {
                pc.ProxyEnabled = false;
            }
            return pc;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            RegistryKey rk = Application.CommonAppDataRegistry;
            rk.SetValue("host",txtProxyHost.Text);
            rk.SetValue("userName", txtProxyUserName.Text);
            rk.SetValue("password",txtProxyPassword.Text);
            rk.SetValue("proxyEnabled", cbUseProxy.Checked);
            this.Close();
        }
    }

    public class ProxyConfigure
    {
        public string Host
        {
            set;
            get;
        }
        public bool? ProxyEnabled
        {
            get;
            set;
        }
        public string UserName
        {
            get;
            set;
        }
        public string Password
        {
            get;
            set;
        }
    }
}
